<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改文件')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-files-edit" th:object="${files}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">
                <label class="col-sm-3 control-label">文件名称：</label>
                <div class="col-sm-8">
                    <input name="filename" th:field="*{filename}" class="form-control" type="text" readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">文件类型：</label>
                <div class="col-sm-8">
                    <input name="contentType" th:field="*{contentType}" class="form-control" type="text" readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">文件大小：</label>
                <div class="col-sm-8">
                    <input name="fileSize" th:field="*{fileSize}" class="form-control" type="text" readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">文件预览：</label>
                <div class="col-sm-8">
                    <!-- 图片预览 -->
                    <div th:if="${files.contentType != null && files.contentType.startsWith('image/')}">
                        <img th:src="@{'/system/files/preview/' + ${files.id}}" style="max-width: 100%; max-height: 300px;">
                    </div>

                    <!-- PDF 预览 -->
                    <div th:if="${files.contentType != null && files.contentType == 'application/pdf'}">
                        <embed th:src="@{'/system/files/preview/' + ${files.id}}" type="application/pdf" width="100%" height="500px" />
                    </div>

                    <!-- 视频预览 -->
                    <div th:if="${files.contentType != null && files.contentType.startsWith('video/')}">
                        <video controls th:src="@{'/system/files/preview/' + ${files.id}}" style="max-width: 100%; max-height: 300px;"></video>
                    </div>

                    <!-- 其他文件：下载链接 -->
                    <div th:if="${files.contentType == null || !(files.contentType.startsWith('image/') or files.contentType.startsWith('video/') or files.contentType == 'application/pdf')}">
                        <a th:href="@{'/system/files/download/' + ${files.id}}" class="btn btn-success btn-xs" target="_blank">
                            <i class="fa fa-download"></i> 下载文件
                        </a>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="remark" class="form-control">[[*{remark}]]</textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script type="text/javascript">
        var prefix = ctx + "system/files";

        $("#form-files-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-files-edit').serialize());
            }
        }
    </script>
</body>
</html>